<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="用工时间" prop="needTime">
        <el-date-picker
          v-model="queryParams.needTime"
          size="mini"
          style="width: 200px"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['job:operationNeed:add']"
        >新增用工需求</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getOperationNeedList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="operationNeedList" >
      <el-table-column type="index" width="150" align="center"/>
      <el-table-column label="用工单id" v-if="show" prop="operationNeedId" width="150"/>
      <el-table-column label="用工单编号" prop="taskNumber" width="150"/>
      <el-table-column label="用工日期" prop="needTime" :show-overflow-tooltip="true" width="200"/>
      <el-table-column label="用工总人数" prop="sumNumber" :show-overflow-tooltip="true" width="200"/>
      <el-table-column label="男性人数" prop="manSumNumber" width="200"/>
      <el-table-column label="女性人数"  prop="womanSumNumber" align="center" width="150"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="taskNode" width="150">
        <template slot-scope="scope">
          <div v-if="scope.row.taskNode == 0">待审核</div>
          <div v-else-if="scope.row.taskNode == 1">已通过</div>
          <div v-else-if="scope.row.taskNode == 2">待修改</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
        <template slot-scope="scope" v-if="scope.row.userId !== 1">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleView(scope.row)">详情</el-button>
          <el-button v-if="scope.row.taskNode !== 1" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['job:operationNeed:edit']">修改</el-button>
          <el-button v-if="scope.row.taskNode == 0" size="mini" type="text" icon="el-icon-edit" @click="handleAudit(scope.row)" v-hasPermi="['job:operationNeed:check']">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['job:operationNeed:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getOperationNeedList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核结果">
                <el-radio-group v-model="form.taskNode">
                  <el-radio :label="1">通过</el-radio>
                  <el-radio :label="2">不通过</el-radio>
                </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="备注">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="addOpen" width="780px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="用工单号">
              <el-input v-model="form.remark" placeholder="请输入用工编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用工日期">
              <el-date-picker
                v-model="queryParams.needTime"
                size="mini"
                style="width: 200px"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24 ">
            <el-form-item label="班次选择">
              <el-checkbox-group v-model="checkList" @change="getCheckBoxValue">
                <el-checkbox class="custom-box"
                             v-for="item in timeShift"
                             :label="item.value"
                             :key="item.value"
                >{{item.text}}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="12" v-for="(item,index) in checkList" v-if="index % 2==0">
          <el-col :span="12">
            <el-row>
              <el-form-item label="班次:">
                {{checkList[index]}}
              </el-form-item>
            </el-row>
            <el-row v-for="(item1,index1) in needNumber" v-if="item1.timeShift==checkList[index]">
              <el-table :data="item1.data" border>
                <el-table-column label="岗位" prop="post" width="163"/>
                <el-table-column label="男性数量/人" prop="man" width="100">
                  <template slot-scope="{row,$index}">
                    <el-input class="edit-cell"  v-model="row.man" />
                  </template>
                </el-table-column>
                <el-table-column label="女性数量/人" prop="woman" width="100">
                  <template slot-scope="{row,$index}">
                    <el-input class="edit-cell"  v-model="row.woman" />
                  </template>
                </el-table-column>
              </el-table>
            </el-row>
          </el-col>

          <el-col :span="12" v-if="index < checkList.length-1">
            <el-row>
              <el-form-item label="班次:">
                {{checkList[index+1]}}
              </el-form-item>
            </el-row>
            <el-row v-for="(item1,index1) in needNumber" v-if="item1.timeShift==checkList[index+1]">
              <el-table :data="item1.data" border>
                <el-table-column label="岗位" prop="post" width="163"/>
                <el-table-column label="男性数量/人" prop="man" width="100">
                  <template slot-scope="{row,$index}">
                    <el-input class="edit-cell"  v-model="row.man" />
                  </template>
                </el-table-column>
                <el-table-column label="女性数量/人" prop="woman" width="100">
                  <template slot-scope="{row,$index}">
                    <el-input class="edit-cell"  v-model="row.woman" />
                  </template>
                </el-table-column>
              </el-table>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getOperationNeedList , addShowOperationNeed , deleteOperationNeed, auditOperationNeed } from "@/api/job/operationNeed/operationNeed";
import { getToken } from "@/utils/auth";
export default {
  name: "attendanceGroup",
  created() {
    this.getOperationNeedList();
  },
  data() {
    return {
      //隐藏id列
      show:false,
      //signUpLoading:true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      operationNeedList: [],
      //班次选择
      checkList:[],
      //班次信息
      timeShift:[{"value":1, "text":"白班"},{"value":2, "text":"夜班"},{"value":3, "text":"下午班"},{"value":4, "text":"凌晨班"}],
      //是否显示编辑弹出层
      addOpen:false,
      //班次需求数据
      needNumber:[
        {"timeShift":1,data:[{"post":"装卸岗","man":11,"woman":0},{"post":"供包岗","man":2,"woman":9}]},
        {"timeShift":2,data:[{"post":"装卸岗","man":12,"woman":0},{"post":"供包岗","man":2,"woman":10}]},
        {"timeShift":3,data:[{"post":"装卸岗","man":13,"woman":0},{"post":"供包岗","man":2,"woman":11}]},
        {"timeShift":4,data:[{"post":"装卸岗","man":14,"woman":0},{"post":"供包岗","man":2,"woman":12}]}
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      signUp:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        needTime:undefined,
      },
      timeShiftList:[],
      // 表单参数
      form: {
        operationNeedId:undefined,
        remark:undefined,
        taskNode:undefined
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },

  methods: {
    /** 获取用工需求列表 */
    getOperationNeedList() {
      this.loading = true;
      getOperationNeedList(this.queryParams).then(
        response => {
          this.operationNeedList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 新增按钮操作 */
    handleAdd() {
     this.$router.push({path:"/operationManagement/need/operationNeedAdd"});
     //this.addOpen = true;
    },
    handleView(row) {
      this.$router.push({path:"/operationManagement/need/operationNeedDetail",query:{operationNeedId:row.operationNeedId}});
    },
    handleUpdate(row){
      this.$router.push({path:"/operationManagement/need/operationNeedUpdate",query:{operationNeedId:row.operationNeedId}});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const operationNeedId = row.operationNeedId || this.ids;
      this.$confirm('是否确认删除的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteOperationNeed(operationNeedId);
        }).then(() => {
          this.getOperationNeedList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /**审核按钮操作*/
    handleAudit(row){
      this.form.operationNeedId = row.operationNeedId;
      this.open = true;
      this.title = "审核";
    },
    // 表单重置
    reset() {
      this.form = {
        needTime:undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getOperationNeedList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    submitForm(){
      auditOperationNeed(this.form).then(es=>{
        this.msgSuccess(es.msg);
        this.open = false;
        this.getOperationNeedList()
      })
    .catch(()=>{
      this.msgError("审核失败");
    })},
    cancel(){
      this.open = false;
      this.form.operationNeedId=undefined;
    },

    getCheckBoxValue(selection){
      for (let i = 0; i < selection.length; i++){
          if(selection[i] == 1){
          }else if (selection[i] == 2){
          }
      }
    }
  }
};
</script>
